﻿using SmartSpace.Orgs;
using SmartSpace.Web;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SmartSpace.WebApp.Modules.Orgs.Pages
{
    public partial class Org_Employee_Assign : SsTemplatePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindEmployeeList();
            }
        }

        public void BindEmployeeList()
        {
            OrgsService service = new OrgsService();
            PagedList<Employee> list = service.GetEmployees("", 0, 9999);
            rep1.DataSource = list;
            rep1.DataBind();
        }

        protected void link_Save_Click(object sender, EventArgs e)
        {
            string ids = this.HDEmployeeIds.Value;
            string nodeId = Request.QueryString["nodeId"] ?? string.Empty;

            OrgsService service = new OrgsService();

            string[] empolyees = ids.Split(',');
            for (int i = 0; i < empolyees.Length; i++)
            {
                service.AssignPost(new Guid(empolyees[i]), new Guid(nodeId), true);
            }
            Response.Redirect("Org-Employee-List.aspx?nodeId=" + nodeId);
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            string nodeId = Request.QueryString["nodeId"] ?? string.Empty;
            Response.Redirect("Org-Employee-List.aspx?nodeId=" + nodeId);
        }
    }
}